﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Server.pages
{
    public partial class FrmSingerEdit : UIForm
    {
        private int _singer_id;

        public int Singer_id { get => _singer_id; set => _singer_id = value; }


        public FrmSingerEdit()
        {
            InitializeComponent();
        }

        private void FrmSingerEdit_Load(object sender, EventArgs e)
        {
            LoadSinger();
        }

        private void LoadSinger()
        {
            // 家里数据库
            string str = "Data Source =.;Initial Catalog=MyKTV;User ID=sa;Password=123@qwe";
            // 学校数据库
            //string str = "Data Source=.;Initial Catalog=MySchool;Persist Security Info=True;User ID=sa;Password=123456@qwe";
            string sql = "select * from sys_singer where id = " + Singer_id;
            SqlConnection connection = new SqlConnection(str);
            connection.Open();
            SqlCommand command = new SqlCommand(sql, connection);
            SqlDataReader reader = command.ExecuteReader();
            if (reader.HasRows)
            {
                if (reader.Read())
                {
                    this.uiTextBox1.Text = (string)reader["sname"];
                }
            }
        }

        private void uiSymbolButton2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void uiSymbolButton1_Click(object sender, EventArgs e)
        {
            // 家里数据库
            string str = "Data Source =.;Initial Catalog=MyKTV;User ID=sa;Password=123@qwe";
            // 学校数据库
            //string str = "Data Source=.;Initial Catalog=MySchool;Persist Security Info=True;User ID=sa;Password=123456@qwe";
            string sql = "update sys_singer set sname = '"+ this.uiTextBox1.Text +"' where id = " + Singer_id;
            SqlConnection connection = new SqlConnection(str);
            connection.Open();
            SqlCommand command = new SqlCommand(sql, connection);
            int number = command.ExecuteNonQuery();
            if (number > 0)
            {
                this.ShowSuccessTip("更新成功！");
                this.Close();
            }
            else
            {
                this.ShowErrorDialog("更新失败！");
            }
        }
    }
}
